package com.x.linx.fenfencard.model.meta;

import com.android.volley.Response;
import com.google.gson.Gson;
import com.x.linx.utils.D;

public class GenerateResponseListener implements Response.Listener<String> {
	IRequestCallback callback;
	Class returnValueClass;

	public GenerateResponseListener(Class returnValueClass,
			IRequestCallback callback) {
		this.callback = callback;
		this.returnValueClass = returnValueClass;
	}

	@Override
	public void onResponse(String response) {
		// response
		D.d("Response", response);
		Gson gson = new Gson();
		ReturnBase ret = gson.fromJson(response, returnValueClass);
		D.d("Response", ret.toString());
		if(null == ret.getContent()){
			callback.fail(ret.getError());
		}else{
			callback.success(ret);
		}
	}
}
